package com.darren.euc.dao.impl;


import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.darren.euc.dao.SpaceDao;
import com.darren.euc.entity.Space;
import com.darren.euc.entity.SpaceStatus;


@Repository
public class SpaceDaoImpl extends BaseDaoImpl<Space, Integer> implements SpaceDao {
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Space> getAll() {
		Session session = sessionFactory.getCurrentSession();	
		//return session.createQuery(" from Space").list();
		String sql = "select space.* from euc_spaces as space INNER JOIN euc_provinces as province on space.province_id = province.province_id and province.`enable` = '1' INNER JOIN euc_cities as city on space.city_id = city.city_id and city.`enable` = '1' order by convert(space_name using gbk) asc;";
		return session.createSQLQuery(sql).addEntity(Space.class).list();
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<SpaceStatus> getAllSpaceStatus(){		
		Session session = sessionFactory.getCurrentSession();	
		return session.createQuery("from SpaceStatus order by statusId asc").list();
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Space> findByIds(List<Integer> ids) {
		Session session = sessionFactory.getCurrentSession();
		Query query  = session.createQuery("from Space where id in (:ids)");
		query.setParameterList("ids", ids);
		return query.list();
	}

}